package com.moly.grpc.nio;

import java.io.*;
import java.nio.channels.FileChannel;

public class TestTrans {

    public static void main(String[] args) throws Exception {


        File from = new File("E:\\moi_files\\a.txt");
        FileInputStream fromIn = new FileInputStream(from);
        FileChannel fromInChannel = fromIn.getChannel();


        File to = new File("E:\\moi_files\\a--_.txt");
        to.createNewFile();
        FileOutputStream toIn = new FileOutputStream(to);
        FileChannel toInChannel = toIn.getChannel();

        transferFrom(from, fromInChannel, toInChannel);
        fromInChannel.close();
        fromIn.close();
        toInChannel.close();
        toIn.close();


    }

    public static void transferFrom(File from,FileChannel fromInChannel, FileChannel toInChannel) {

        try {
            long l = toInChannel.transferFrom(fromInChannel, 0, from.length());
            System.out.println(" l "+l);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void transferTo(File from,FileChannel fromInChannel, FileChannel toInChannel) {

        try {
            fromInChannel.transferTo(0, from.length(), toInChannel);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
